import random
import string

from django.shortcuts import render
from django.http.response import JsonResponse
from pyexpat.errors import messages
from django.core.mail import send_mail


# Create your views here.
def login(request):
    return render(request,'login.html')

def register(request):
    return render(request,'register.html')

def send_email_captcha(request):
    email = request.GET.get('email')
    if not email:
        return JsonResponse({"code":400, "message":'需要填入邮箱'})
    # 生成验证码，4位随机阿拉伯数字
    captcha = "".join(random.sample(string.digits,4))
    send_mail("测试验证码",message=f"您的验证码是:{captcha}",recipient_list=[email],from_email="None")
    return JsonResponse({"code": 200, "message": '验证码已发送'})